﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace MyWpf.Command
{
	public class DelegateCommand : ICommand
	{
		public event EventHandler? CanExecuteChanged;
		public Action<Object> ExecuteAction { get; set; }
		public Func<object, bool> CanExecuteFunc { get; set; }

		public bool CanExecute(object? parameter)
		{
			if(CanExecuteFunc != null)
			{
				return CanExecuteFunc(parameter);
			}
			return true;
		}

		public void Execute(object? parameter)
		{
			if (ExecuteAction != null)
			{
				ExecuteAction(parameter);
			}
		}
	}
}
